package com.demo.zyt.modules.app.wechatsdk;

import java.io.ByteArrayInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.InputStream;

import com.demo.zyt.common.exception.RRException;
import com.demo.zyt.common.utils.AppResultEnum;
import com.demo.zyt.modules.app.utils.WeChatUtils;

public class WeChatPayConfig extends WXPayConfig{

	private byte[] certData;

    public WeChatPayConfig(String certPath) {
    	try {
	        File file = new File(certPath);
	        InputStream certStream = new FileInputStream(file);
	        this.certData = new byte[(int) file.length()];
	        certStream.read(this.certData);
	        certStream.close();
    	}catch ( Exception e ) {
    		throw new RRException(AppResultEnum.SYSTEM_ERROR);
    	}
    }

    public String getAppID() {
        return WeChatUtils.APP_ID;
    }

    public String getMchID() {
        return WeChatUtils.MCH_ID;
    }

    public String getKey() {
        return WeChatUtils.MCH_KEY;
    }

    public InputStream getCertStream() {
        ByteArrayInputStream certBis = new ByteArrayInputStream(this.certData);
        return certBis;
    }

    public int getHttpConnectTimeoutMs() {
        return 8000;
    }

    public int getHttpReadTimeoutMs() {
        return 10000;
    }

	@Override
	IWXPayDomain getWXPayDomain() {
		IWXPayDomain iwxPayDomain = new IWXPayDomain() {
            @Override
            public void report(String domain, long elapsedTimeMillis, Exception ex) {

            }
            @Override
            public DomainInfo getDomain(WXPayConfig config) {
                return new IWXPayDomain.DomainInfo(WXPayConstants.DOMAIN_API, true);
            }
        };
        return iwxPayDomain;
	}

}
